package com.rlyy.common.utils;

import com.rlyy.common.enums.CommonEnum;
import com.rlyy.common.enums.ExceptionEnum;
import com.rlyy.common.exception.ArgsMissingException;
import org.springframework.util.ObjectUtils;

/**
 * @author yuanqinglong
 * @since 2020/6/9 15:54
 */
public class CommonUtil {


    public static void checkParamsIntegrity(Object... params) {
        if (!paramsEnough(params)) {
            throw new ArgsMissingException(CommonEnum.PARAMS_NOT_ENOUGH);
        }
    }

    public static void checkParamsIntegrity(ExceptionEnum exceptionEnum, Object... params) {
        if (!paramsEnough(params)) {
            throw new ArgsMissingException(exceptionEnum);
        }
    }

    /**
     * 检验参数是否不足
     *
     * @param params 参数
     * @return 状态
     */
    public static boolean paramsEnough(Object... params) {
        for (Object param : params.clone()) {
            if (ObjectUtils.isEmpty(param)) {
                return false;
            }
        }
        return true;
    }


    /**
     * 驼峰命名转下划线命名
     * 小写和大写紧挨一起的地方,加上分隔符,然后全部转小写
     */
    public static String camel2under(String c) {
        String separator = "_";
        c = c.replaceAll("([a-z])([A-Z])", "$1" + separator + "$2").toLowerCase();
        return c;
    }

}
